package com.jsh.erp.service.WorkflowConfigProcess;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "workflowConfigProcess_component")
@WorkflowConfigProcessResource
public class WorkflowConfigProcessComponent implements ICommonQuery {

    @Resource
    private WorkflowConfigProcessService workflowConfigProcessService;
    @Resource
    private RedisService redisService;
    @Override
    public Object selectOne(String id) throws Exception {
        return workflowConfigProcessService.getWorkflowConfigProcess(id);
    }

    @Override
    public List<?> select(Map<String, String> map)throws Exception {
        return getWorkflowDefMainList(map);
    }

    private List<?> getWorkflowDefMainList(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String taskTitle = StringUtil.getInfo(search, "taskTitle");
        return workflowConfigProcessService.select(taskTitle,QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String taskTitle = StringUtil.getInfo(search, "taskTitle");
        return workflowConfigProcessService.countWorkflowConfigProcess(taskTitle);
    }

      @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
        obj.put("id", IdUtils.getUUID());
        return workflowConfigProcessService.insertWorkflowConfigProcess(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request)throws Exception {
        return workflowConfigProcessService.updateWorkflowConfigProcess(obj, request);
    }

    @Override
    public int delete(String id, HttpServletRequest request)throws Exception {
        return workflowConfigProcessService.deleteWorkflowConfigProcess(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
        return workflowConfigProcessService.batchDeleteWorkflowConfigProcess(ids, request);
    }

    @Override
     public int checkIsNameExist(String id, String name) throws Exception{
        return workflowConfigProcessService.checkIsNameExist(id, name);
    }

}
